home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / etc / init.d / umountfs < prev    next >
Encoding:
Text File  |  2006-10-06  |  3.4 KB  |  176 lines

  1. #! /bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides:          umountfs
  4. # Required-Start:    umountnfs urandom
  5. # Required-Stop:
  6. # Default-Start:     0 6
  7. # Default-Stop:
  8. # Short-Description: Turn off swap and unmount all local file systems.
  9. # Description:
  10. ### END INIT INFO
  11.  
  12. PATH=/usr/sbin:/usr/bin:/sbin:/bin
  13. . /lib/init/vars.sh
  14.  
  15. . /lib/lsb/init-functions
  16.  
  17. umask 022
  18.  
  19. # Print in order of decreasing length
  20. #
  21. # Algorithm: Find and print longest argument, then call self
  22. # to print remaining arguments in order of decreasing length
  23. #
  24. # This function runs at one tenth the speed of the sort program
  25. # but we use the function because we don't want to rely on any
  26. # programs in /usr/.
  27. #
  28. # N.B.: Arguments must not be null and must not contain whitespace
  29. #
  30. pioodl() {
  31.     [ "$1" ] || return 0
  32.     ARGNUM=1
  33.     ARGNUM_LONGEST=0
  34.     ARGLENGTH_LONGEST=0
  35.     for ARG in "$@"
  36.     do
  37.         ARGLENGTH="${#ARG}"
  38.         if [ "$ARGLENGTH" -gt "$ARGLENGTH_LONGEST" ]
  39.         then
  40.             ARGLENGTH_LONGEST="$ARGLENGTH"
  41.             ARGNUM_LONGEST="$ARGNUM"
  42.         fi
  43.         ARGNUM=$(($ARGNUM + 1))
  44.     done
  45.     # The method of passing prevargs assumes that args can be
  46.     # delimited with spaces
  47.     ARGNUM=1
  48.     PREVARGS=""
  49.     while [ "$ARGNUM" -lt "$ARGNUM_LONGEST" ]
  50.     do
  51.         PREVARGS="$PREVARGS $1"
  52.         shift
  53.         ARGNUM=$(($ARGNUM + 1))
  54.     done
  55.     echo "$1"
  56.     shift
  57.     pioodl $PREVARGS "$@"
  58. }
  59.  
  60.  
  61. do_stop () {
  62.     exec 9<&0 </proc/mounts
  63.  
  64.     REG_MTPTS=""
  65.     TMPFS_MTPTS=""
  66.     while read DEV MTPT FSTYPE REST
  67.     do
  68.         case "$MTPT" in
  69.           /|/proc|/dev|/.dev|/dev/pts|/dev/shm|/proc/*|/sys|/var/run|/var/lock)
  70.             continue
  71.             ;;
  72.         esac
  73.         case "$FSTYPE" in 
  74.           proc|procfs|linprocfs|devfs|sysfs|usbfs|usbdevfs|devpts)
  75.             continue
  76.             ;;
  77.           tmpfs)
  78.             TMPFS_MTPTS="$TMPFS_MTPTS $MTPT"
  79.             ;;
  80.           *)
  81.             REG_MTPTS="$REG_MTPTS $MTPT"
  82.             ;;
  83.         esac
  84.     done
  85.  
  86.     exec 0<&9 9<&-
  87.     
  88.     #
  89.     # Make sure tmpfs file systems are umounted before turning off
  90.     # swap, to avoid running out of memory if the tmpfs filesystems
  91.     # use a lot of space.
  92.     #
  93.     if [ "$TMPFS_MTPTS" ]
  94.     then
  95.         if [ "$VERBOSE" = no ]
  96.         then
  97.             log_action_begin_msg "Unmounting temporary filesystems"
  98.             umount $TMPFS_MTPTS
  99.             log_action_end_msg $?
  100.         else
  101.             log_action_msg "Will now unmount temporary filesystems"
  102.             umount -v $TMPFS_MTPTS
  103.             ES=$?
  104.             if [ "$ES" = 0 ]
  105.             then
  106.                 log_success_msg "Done unmounting temporary filesystems."
  107.             else
  108.                 log_failure_msg "Unmounting temporary filesystems failed with error code ${ES}."
  109.             fi
  110.         fi
  111.     fi
  112.  
  113.     #
  114.     # Deactivate swap
  115.     #
  116.     if [ "$VERBOSE" = no ]
  117.     then
  118.         log_action_begin_msg "Deactivating swap"
  119.         swapoff -a >/dev/null
  120.         log_action_end_msg $?
  121.     else
  122.         log_action_msg "Will now deactivate swap"
  123.         swapoff -a -v
  124.         ES=$?
  125.         if [ "$ES" = 0 ]
  126.         then
  127.             log_success_msg "Done deactivating swap."
  128.         else
  129.             log_failure_msg "Swap deactivation failed with error code ${ES}."
  130.         fi
  131.     fi
  132.  
  133.     #
  134.     # Unmount local filesystems
  135.     #
  136.     if [ "$REG_MTPTS" ]
  137.     then
  138.         REG_MTPTS="$(pioodl $REG_MTPTS)"
  139.         if [ "$VERBOSE" = no ]
  140.         then
  141.             log_action_begin_msg "Unmounting local filesystems"
  142.             umount -f -r -d $REG_MTPTS
  143.             log_action_end_msg $?
  144.         else
  145.             log_action_msg "Will now unmount local filesystems"
  146.             umount -f -v -r -d $REG_MTPTS
  147.             ES=$?
  148.             if [ "$ES" = 0 ]
  149.             then
  150.                 log_success_msg "Done unmounting local filesystems."
  151.             else
  152.                 log_failure_msg "Unmounting local filesystems failed with error code ${ES}."
  153.             fi
  154.         fi
  155.     fi
  156. }
  157.  
  158. case "$1" in
  159.   start)
  160.     # No-op
  161.     ;;
  162.   restart|reload|force-reload)
  163.     echo "Error: argument '$1' not supported" >&2
  164.     exit 3
  165.     ;;
  166.   stop)
  167.     do_stop
  168.     ;;
  169.   *)
  170.     echo "Usage: $0 start|stop" >&2
  171.     exit 3
  172.     ;;
  173. esac
  174.  
  175. :
  176.